local tuizhi = fk.CreateSkill{
  name = "th_tuizhi",
  max_branches_use_time = function(self, player)
    local ret = {}
    for _, p in ipairs(Fk:currentRoom().players) do
      ret[tostring(p.id)] = {
        [Player.HistoryTurn] = 1
      }
    end
    return ret
  end
}

tuizhi:addEffect(fk.TargetSpecified, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target ~= player and data.card and data.card.trueName == "slash" and player:hasSkill(tuizhi.name) and not player:isNude() and
    tuizhi:withinBranchTimesLimit(player, tostring(target.id)) and player:inMyAttackRange(target)
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    ---@type CostData|UseCardDataSpec
    local use = room:askToUseCard(player, {
      pattern = "slash",
      skill_name = tuizhi.name,
      prompt = "#th_tuizhi-ask::" .. target.id,
      cancelable = true,
      extra_data = {
        must_targets = {target.id},
        exclusive_targets = {target.id},
        bypass_distances = true,
        bypass_times = true
      }
    })
    if use then
      event:setCostData(self, { tos = use.tos, use_data = use, history_branch = tostring(target.id) })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local use = event:getCostData(self).use_data
    local room = player.room
    room:useCard(use)
    if use.damageDealt then
      data:setNullified(table.simpleClone(room.players))
    end
  end,
}, { check_skill_limit = true })

tuizhi:addTest(function(room, me)
  local comp2 = room.players[2]
  local jink = room:printCard("jink")
  local slash = Fk:getCardById(1)
  local slashB = Fk:getCardById(2)

  --- test: comp2对me使用【杀】
  --- 期望: me发动技能，此【杀】对me无效
  FkTest.RunAddSkills(me, tuizhi.name)
  FkTest.setNextReplies(comp2, {
    FkTest.replyCard(slashB, {me})
  })
  FkTest.setNextReplies(me, {
    FkTest.replyCard(slash, {comp2})
  })
  FkTest.runInRoom(function()
    room:obtainCard(me, slash)
    comp2:gainAnExtraTurn(false)
  end)
  lu.assertEquals(me.hp, 4)
end)

Fk:loadTranslationTable{
  ["th_tuizhi"] = "退治",
  [":th_tuizhi"] = "每回合每名角色限一次，你攻击范围内的角色使用【杀】指定目标后，你可以对其使用一张【杀】，此【杀】造成伤害后，你令使用者使用的【杀】无效。",

  ["#th_tuizhi-ask"] = "退治：你可以对 %dest 使用一张【杀】",
}

return tuizhi
